package demo05;

import java.util.ArrayList;
import java.util.Random;
//群主
public class Player {
	private String name;
	private int money;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getMoney() {
		return money;
	}
	public void setMoney(int money) {
		this.money = money;
	}
	public Player(String name, int money) {
		this.name = name;
		this.money = money;
	}
	public Player() {
	}
	public void show(){
		System.out.println("姓名："+name+", 金钱："+money);
	}


	//发送红包
	public  ArrayList<Integer> send(int totalMoney,int count){
		ArrayList<Integer> redList=new ArrayList<Integer>();
		//钱是否足够
		int leftMoney = this.getMoney();
		if(totalMoney>leftMoney){
			System.out.println("余额不足");
			return null;
		}
		//计算余额
		this.setMoney(leftMoney-totalMoney);
		//红包金额计算
		int avg=totalMoney/count;
		int mod=totalMoney%count;// 多出来的零钱
		//平均分发
		for(int i=0;i<count-1;i++){
			redList.add(avg);
		}
		//最后一个
		int last=avg+mod;
		redList.add(last);
		return redList;
	}
	public ArrayList<Integer> sendnew(int totalMoney ,int count){
		ArrayList<Integer> redList=new ArrayList<Integer>();
		int leftMoney = this.getMoney();
		if(totalMoney>leftMoney){
			System.out.println("余额不足");
			return null;
		}
		this.setMoney(leftMoney-totalMoney);
		for(int i=1;i<count;i++) {
			
			int bag=new Random().nextInt(totalMoney/(count-i+1)*2)+1;
			redList.add(bag);
			totalMoney-=bag;
		}
		int last = totalMoney;
		redList.add(last);
		return redList;
	}
}
